package com.teame.readbaby.parser;

import java.util.List;

import org.json.JSONException;

import com.alibaba.fastjson.JSONObject;
import com.teame.readbaby.util.Logger;
import com.teame.readbaby.vo.CheckOutAddressInfo;
import com.teame.readbaby.vo.CheckOutAddup;
import com.teame.readbaby.vo.CheckOutDelivery;
import com.teame.readbaby.vo.CheckOutInfo;
import com.teame.readbaby.vo.CheckOutInvoiceInfo;
import com.teame.readbaby.vo.CheckOutPayment;
import com.teame.readbaby.vo.CheckOutProductInfo;

/**
 * 结算中心解析器
 * @author wang_xiaohao
 *
 */
public class CheckOutParser extends BaseParser<Object> {

	public static final String TAG = "CheckOutParser";

	/**
	 * 结算中心的解析器 参数：paramString
	 */
	@Override
	public CheckOutInfo parseJSON(String paramString) throws JSONException {
		// 检查是否为null；
		String result = checkResponse(paramString);
		if (result == null) {
			return null;
		} else {
			JSONObject jsonObject = JSONObject.parseObject(paramString);
			System.out.println("jsonObject内容："+jsonObject);
			
			//可以获得 checkoutInfo 所有字段；
			String checkoutInfo = jsonObject.getString("checkoutInfo");
			System.out.println("checkoutInfo:::::"+checkoutInfo);
			
			
			//在此转换陈对象，在此基础上获得 address_info；
			JSONObject jsonObject_checkoutInfo = JSONObject.parseObject(checkoutInfo);
			//结算中心类集合
			CheckOutInfo checkinfo = new CheckOutInfo();
			
			//地址信息
			String address_info = jsonObject_checkoutInfo.getString("address_info");
			CheckOutAddressInfo addressInfo = JSONObject.parseObject(address_info,CheckOutAddressInfo.class);
			Logger.i(TAG, addressInfo.toString());
			checkinfo.setAddressInfo(addressInfo);
			
			//总共计算
			String checkout_addup = jsonObject_checkoutInfo.getString("checkout_addup");
			CheckOutAddup addup = JSONObject.parseObject(checkout_addup, CheckOutAddup.class);
			Logger.i(TAG, addup.toString());
			checkinfo.setCheckoutAddup(addup);
			
			//送货时间
			String delivery_info = jsonObject_checkoutInfo.getString("delivery_info");
			CheckOutDelivery delivery = JSONObject.parseObject(delivery_info, CheckOutDelivery.class);
			Logger.i(TAG, delivery.toString());
			checkinfo.setDeliveryInfo(delivery);
			
			//发票
			String invoiceInfo_info = jsonObject_checkoutInfo.getString("invoiceInfo");
			CheckOutInvoiceInfo invoiceInfo = JSONObject.parseObject(invoiceInfo_info, CheckOutInvoiceInfo.class);
			Logger.i(TAG, invoiceInfo.toString());
			checkinfo.setInvoiceInfo(invoiceInfo);
			
			//支付属性信息
			String payment_info = jsonObject_checkoutInfo.getString("payment_info");
			CheckOutPayment payment = JSONObject.parseObject(payment_info, CheckOutPayment.class);
			Logger.i(TAG, payment.toString());
			checkinfo.setPaymentInfo(payment);
			
			//商品信息集合 list
			String productlist = jsonObject_checkoutInfo.getString("productlist");
			Logger.i(TAG, "集合信息："+productlist);
			List<CheckOutProductInfo> prolist = JSONObject.parseArray(productlist, CheckOutProductInfo.class);
			Logger.i(TAG, prolist.size()+"");
			checkinfo.setProductlist(prolist);
			
			
//			"product_property":[],//属性**********
//			"checkout_prom":[],//享受促销信息 无 *****
			String product_property = jsonObject_checkoutInfo.getString("product_property");
			String checkout_prom = jsonObject_checkoutInfo.getString("checkout_prom");
			Logger.i(TAG, "product_property:::"+product_property+"\ncheckout_prom"+checkout_prom);

			
			Logger.i(TAG, "大集合：checkinfo"+checkinfo.toString());
			return checkinfo;
		}

	}
	

}
